//
//  ListAsignaturas_VC.m
//  MasterUabApp
//
//  Created by Developer on 14/10/13.
//  Copyright (c) 2013 Owlab. All rights reserved.
//

//---Imports:--
#import "ListAsignaturas_VC.h"
#import "Asignatura_Cell.h"
//-------------

@interface ListAsignaturas_VC ()

@end

@implementation ListAsignaturas_VC

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.

    [self loadAsignaturas];
}


- (void) loadAsignaturas
{
    if (m_AlumnoArray == nil)
    {
        m_AlumnoArray = [[AlumnoArray alloc]init:self];
    }
    [ECommon showProgressInView:self.view withText:@"LOADING..."];
    [m_AlumnoArray getAsignaturas:_alumnoID];
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void) syncDone:(BOOL)success object:(BaseObject*)obj
{
    if (success)
    {
        if ([obj isKindOfClass:[AlumnoArray class]])
        {
            [ECommon hideProgress];
            [_m_TableView reloadData];
        }
    }
    else
    {
        //Show error message
        if (obj!=nil && obj.msg != nil && obj.msg.length > 0)
        {
            [ECommon setProgressDetailsLabel:obj.msg];
            [ECommon setProgressErrorAndHideWithText:NSLocalizedString(@"Problem detected:", @"")];
        }
        else
        {
            [ECommon setProgressErrorAndHideWithText:NSLocalizedString(@"Connection error", @"")];
        }
    }
}

#pragma mark - Table view data source

-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 57.f;
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return m_AlumnoArray.arrayAsignaturas.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Asignatura_Cell";
    Asignatura_Cell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    Asignatura* asignatura = [m_AlumnoArray.arrayAsignaturas objectAtIndex:indexPath.row];
    // Configure the cell...
    if (cell == nil)
    {
        cell = [[Asignatura_Cell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    
    cell.m_Label_Name.text      = asignatura.AsignaturaNombre;
    cell.m_Label_Creditos.text  = asignatura.AsignaturaCreditos;
    return cell;
}

@end
